package com.fengye.security.captcha.authentication.security.beans;

import lombok.Getter;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * @author sky
 * @date 2021年06月01日 11:39 上午
 */

@Getter
public class MyWebAuthenticationDetails extends WebAuthenticationDetails {

    private String imageCode;
    private String savedImageCode;
    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        this.imageCode = request.getParameter("captcha");
        HttpSession session = request.getSession();
        String captcha = (String) session.getAttribute("captcha");
        this.savedImageCode = captcha;

        // 只要读取过一次 session 中存在的验证码,立马清除,客户端刷新
        if (StringUtils.hasText(captcha)) {
            session.removeAttribute("captcha");
        }


    }
}
